1
บทเรียนที่ 7: การเรียนรู้แบบถ่ายทอด – การใช้ความรู้อย่างมีประสิทธิภาพ
EvoClass-AI002Lecture 7
00:00

ยินดีต้อนรับสู่บทเรียนที่ 7 ซึ่งเราจะแนะนำ การเรียนรู้แบบถ่ายทอด. เทคนิคนี้เกี่ยวข้องกับการนำโมเดลการเรียนรู้เชิงลึกที่ได้รับการฝึกอบรมแล้วจากชุดข้อมูลขนาดใหญ่และทั่วไป (เช่น ImageNet) มาใช้ใหม่ และปรับให้เหมาะสมกับงานเฉพาะเจาะจงที่แตกต่างกัน (เช่น โครงการอาหารของเรานั่นเอง) มันเป็นสิ่งจำเป็นสำหรับการบรรลุผลลัพธ์ระดับสูงสุดอย่างมีประสิทธิภาพ โดยเฉพาะเมื่อชุดข้อมูลที่มีป้ายกำกับมีจำกัด

1. ศักยภาพของการใช้น้ำหนักที่ฝึกเสร็จแล้ว

เครือข่ายประสาทเทียมลึกเรียนรู้คุณสมบัติตามลำดับชั้น ชั้นต่ำเรียนรู้แนวคิดพื้นฐาน (เส้นขอบ แฉก ลวดลาย) ในขณะที่ชั้นที่ลึกกว่ารวมสิ่งเหล่านี้เข้าด้วยกันเป็นแนวคิดที่ซับซ้อน (ดวงตา ล้อ วัตถุเฉพาะ) ประเด็นสำคัญคือ คุณสมบัติพื้นฐานที่เรียนรู้ในช่วงแรกนั้น สามารถนำไปใช้ได้ทั่วไป ครอบคลุมโดเมนภาพส่วนใหญ่

องค์ประกอบของการเรียนรู้แบบถ่ายทอด

  • งานต้นทาง: การฝึกอบรมบนภาพจำนวน 14 ล้านภาพ และ 1,000 หมวดหมู่ (เช่น ImageNet)
  • งานปลายทาง: การปรับน้ำหนักเพื่อจัดประเภทชุดข้อมูลที่เล็กลงมาก (เช่น ชั้นอาหารเฉพาะของเรา)
  • ส่วนที่ใช้ประโยชน์: พารามิเตอร์ส่วนใหญ่ของเครือข่าย — ชั้นการดึงคุณสมบัติ — ถูกนำมาใช้ใหม่โดยตรง
ข้อได้เปรียบด้านประสิทธิภาพ
การเรียนรู้แบบถ่ายทอดลดอุปสรรคด้านทรัพยากรหลักสองประการอย่างมาก: ต้นทุนด้านการคำนวณ (คุณหลีกเลี่ยงการฝึกโมเดลทั้งหมดเป็นเวลาหลายวัน) และ ข้อกำหนดด้านข้อมูล (สามารถบรรลุความแม่นยำสูงได้ด้วยตัวอย่างการฝึกเพียงไม่กี่ร้อยตัว แทนที่จะเป็นหลายพันตัว)
train.py
TERMINALbash — pytorch-env
> Ready. Click "Run" to execute.
>
TENSOR INSPECTOR Live

Run code to inspect active tensors
Question 1
What is the primary advantage of using a model pre-trained on ImageNet for a new vision task?
It requires less labeled data than training from scratch.
It completely eliminates the need for any training data.
It guarantees 100% accuracy immediately.
Question 2
In a Transfer Learning workflow, which part of the neural network is typically frozen?
The final Output Layer (Classifier Head).
The Convolutional Base (Feature Extractor layers).
The entire network is usually unfrozen.
Question 3
When replacing the classifier head in PyTorch, what parameter must you first determine from the frozen base?
The batch size of the target data.
The input feature size (the output dimensions of the last convolutional layer).
The total number of model parameters.
Challenge: Adapting the Classifier Head
Designing a new classifier for FoodVision.
You load a ResNet model pre-trained on ImageNet. Its last feature layer outputs a vector of size 512. Your 'FoodVision' project has 7 distinct food classes.
Step 1
What is the required Input Feature size for the new, trainable Linear Layer?
Solution:
The Input Feature size must match the output of the frozen base layer.
Size: 512.
Step 2
What is the PyTorch code snippet to create this new classification layer (assuming the output is named `new_layer`)?
Solution:
The output size of 512 is the input, and the class count 7 is the output.
Code: new_layer = torch.nn.Linear(512, 7)
Step 3
What is the required Output Feature size for the new Linear Layer?
Solution:
The Output Feature size must match the number of target classes.
Size: 7.